package data;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//import java.util.*;
//import oracle.jdbc.pool.OracleDataSource;

public class User_Login {
	private Connection conn;
	//private static String connectionString = "jdbc:oracle:thin:isstest/Oracle123@portal.oracle.vn:1521:orcl";
	
	public User_Login(Connection conn){
		this.conn = conn;
	}

	public UserInfo querryUser(String usr, String pwd){
            Statement select;
            UserInfo user = null;
            try {
                select = conn.createStatement();
                String table = "USERTBL";
                String strQuery = "Select * from " + table +" where username='" + usr + "' and password = '"+ Constant.md5hash(pwd) + "'";
                System.out.println(strQuery);
                ResultSet result = select.executeQuery(strQuery);
                
                //System.out.println(result.next());
                while(result.next()){
                    user = new UserInfo();
                    user.setID(result.getInt(1));
                    user.setUsername(result.getString(2));
                    user.setPwd(pwd);
                    user.setDefTbspace(result.getString(4));
                    user.setTmpTbspace(result.getString(5));
                    user.setAccStatus(result.getString(6));
                    user.setQuota(result.getString(7));
                    user.setProfile(result.getString(8));
                    user.setRole(result.getString(9));
                    System.out.println(result.getString(8) + " " + user.getProfile());
                    if(user.getAccStatus().equals("LOCK")){
                        return null;
                    }
                    //System.out.println(uid + ":" + username);
                }
                    
            } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    System.out.println(e);
            }
            return user;
	}
	
//	public void closeConnection(){
//            if(conn != null)
//                try {
//                    conn.close();
//                } catch (SQLException e) {
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                }
//	}
}
